package com;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import com.util.RabbitmqUtils;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class ConsumerApp3 {
    public static void main(String[] args) {
        while (true) {
            DeliverCallback deliverCallback = new DeliverCallback() {
                @Override
                public void handle(String consumerTag, Delivery message) throws IOException {
                    byte[] body = message.getBody();
                    String content = new String(body);
                    try {
                        if (content.equals("dll2")) {
                            System.out.println("消费者3号未完成消费" + content);
//                            throw new RuntimeException();
                            return;
                        }
                    } catch (RuntimeException e) {
                        e.printStackTrace();
                    }
                    System.out.println("消费者3消费了消息：" + content);
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            CancelCallback cancelCallback = new CancelCallback() {
                @Override
                public void handle(String consumerTag) throws IOException {
                    System.out.println("消费者3号取消消费");
                }
            };
            RabbitmqUtils.receiveByWQ("test2", false, false, false,
                    null, deliverCallback, cancelCallback);
        }
    }
}
